package com.ihy.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

/**
 * 文件操作工具类
 */
public class FileOperateUtil {

    /**
     * 读取本地html文件里的html代码
     */
    public static String toHtmlString(File file) {
        StringBuilder htmlSb = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8));
            while (br.ready()) {
                htmlSb.append(br.readLine());
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return htmlSb.toString();
    }
}
